# encoding: utf-8

module Merge
  # 发送合并请求（user_two 发送）
  def send_merge_request(data)
    title = data['title']
    desc = data['desc']

    # 点击合并请求按钮
    @driver.find_element(:link, "合并请求").click

    @driver.find_element(:id, "merge_request_title").clear
    @driver.find_element(:id, "merge_request_title").send_keys title
    @driver.find_element(:id, "textarea").clear
    @driver.find_element(:id, "textarea").send_keys desc
    @driver.find_element(:id, "new_note_form_submit").click
  end

  # 处理合并请求(user_one 处理)
  def handel_merge_request(merge)
    go_merge_page_by_title(merge['title'])

    # 自动合并
    @driver.find_element(:link, "合并").click
  end

  # 进入合并请求列表页
  def go_merge_list
    @driver.find_element(:xpath, "//a[@href='/dashboard/merge_requests']").click
  end

  # 进入特定标题的合并请求处理页面
  def go_merge_page_by_title(title, is_complete = false)
    # 进入合并请求列表页
    go_merge_list

    if is_complete then
      @driver.find_element(:link, '已完成').click
    end

    # 进入标题为title的合并请求处理页面
    @driver.find_element(:link, "#{title}").click
  end
end